//
//  CFTabBarController.m
//  WealthElves
//
//  Created by Wealthwiz on 2017/4/25.
//  Copyright © 2017年 Wealthwiz. All rights reserved.
//

#import "CFTabBarController.h"

#import "LFHomePageViewController.h"
#import "LFEgovenmentServiceViewController.h"
#import "LFNationalRegulationViewController.h"
#import "LFConvenienceServiceViewController.h"
#import "LFMyViewController.h"

@interface CFTabBarController ()

@end

@implementation CFTabBarController
+ (void)initialize
{
    // 获取所有的tabBarItem外观标识
    //    UITabBarItem *item = [UITabBarItem appearance];
    
    // self -> CZTabBarController
    // 获取当前这个类下面的所有tabBarItem
//    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
//    
//    NSMutableDictionary *att = [NSMutableDictionary dictionary];
//    att[NSForegroundColorAttributeName] = [UIColor colorWithRed:222/255.0 green:195/255.0 blue:118/255.0 alpha:1];
//    //[att setObject:[UIColor colorWithRed:222/255 green:195/255.0 blue:118/255.0 alpha:1] forKey:NSForegroundColorAttributeName];
//    
//    [item setTitleTextAttributes:att forState:UIControlStateSelected];
}
+(CFTabBarController *)sharedTabBar
{
    static dispatch_once_t once;
    static CFTabBarController *shareTabbar;
    dispatch_once(&once, ^ {
        shareTabbar = [[self alloc] init];
    });
    return shareTabbar;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    //[self.tabBar setBackgroundImage:[UIImage imageNamed:@"CF_Tabbar_BG"]];
    //[self.tabBar setBackgroundImage:[[UIImage alloc] init]];
   // [self.tabBar setBarTintColor:kRGBA(252, 252, 252, 1.0)];
    //[self.tabBar setShadowImage:[[UIImage alloc] init]];
    //[UITabBar appearance].translucent = NO;
//    
//    CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width);
//    
//    UIGraphicsBeginImageContext(rect.size);
//    
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    
//    CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
//    
//    CGContextFillRect(context, rect);
//    
//    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
//    
//    UIGraphicsEndImageContext();
//    
//    [self.tabBar setBackgroundImage:img];
//    
//    [self.tabBar setShadowImage:img];
//    
//    //[self.tabBar setBackgroundColor:[UIColor whiteColor]];
//    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"CF_Tabbar_BG_1.png"]];
    // 添加所有子控制器
    [self setUpAllChildViewController];
}
- (void)setUpAllChildViewController
{
    UINavigationController *homePage = [[UINavigationController alloc] initWithRootViewController:[[LFHomePageViewController alloc] init]];
    [self setUpOneChildViewController:homePage image:[UIImage imageNamed:@"CF_Tabbar_Financial"] selectedImage:[UIImage imageNamed:@"CF_Tabbar_Financial_S"] title:@"首页"];
    
    UINavigationController *egovenmentService = [[UINavigationController alloc] initWithRootViewController:[[LFEgovenmentServiceViewController alloc] init]];
    [self setUpOneChildViewController:egovenmentService image:[UIImage imageNamed:@"CF_Tabbar_Combination"] selectedImage:[UIImage imageNamed:@"CF_Tabbar_Combination_S"] title:@"政务服务"];
    
    UINavigationController *nationalRegulation = [[UINavigationController alloc] initWithRootViewController:[[LFNationalRegulationViewController alloc] init]];
    [self setUpOneChildViewController:nationalRegulation image:[UIImage imageNamed:@"CF_Tabbar_Market"] selectedImage:[UIImage imageNamed:@"CF_Tabbar_Market_S"] title:@"全民监管"];
    
    UINavigationController *convenienceService = [[UINavigationController alloc] initWithRootViewController:[[LFConvenienceServiceViewController alloc] init]];
    [self setUpOneChildViewController:convenienceService image:[UIImage imageNamed:@"CF_Tabbar_My"] selectedImage:[UIImage imageNamed:@"CF_Tabbar_My_S"] title:@"便民服务"];
    
    UINavigationController *my = [[UINavigationController alloc] initWithRootViewController:[[LFMyViewController alloc] init]];
    [self setUpOneChildViewController:my image:[UIImage imageNamed:@"CF_Tabbar_My"] selectedImage:[UIImage imageNamed:@"CF_Tabbar_My_S"] title:@"我的"];
    
    
}
- (void)setUpOneChildViewController:(UIViewController *)vc image:(UIImage *)image selectedImage:(UIImage *)selectedImage title:(NSString *)title
{
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = image;
    vc.tabBarItem.selectedImage = selectedImage;
    [self addChildViewController:vc];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
